#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
using namespace std;

const int N = 55, INF = 0x3f3f3f3f;

int n, m;
char a[N][N];
bool vis[N][N];
const int d[8][2] = { -1,0,-1,1,0,1,1,1,1,0,1,-1,0,-1,-1,-1 };

void bfs(pair<int, int> s) {
    queue<pair<int, int> > q;
    q.push(s);vis[s.first][s.second] = 1;
    while (!q.empty()) {
        auto [x, y] = q.front();q.pop();
        for (int i = 0;i < 8;i++) {
            int nx = x + d[i][0], ny = y + d[i][1];
            if (nx >= 1 && nx <= n && ny >= 1 && ny <= m && a[nx][ny] == '.' && vis[nx][ny] == 0) {
                q.push({ nx,ny });
                vis[nx][ny] = 1;
            }
        }
    }
}

void solve()
{
    while (cin >> n >> m) {
        memset(vis, 0, sizeof vis);

        for (int i = 1;i <= n;i++)
            for (int j = 1;j <= m;j++)
                cin >> a[i][j];

        for (int i = 1;i <= n;i++) {
            if (a[i][1] == '.' && vis[i][1] == 0) bfs({ i,1 });
            if (a[i][m] == '.' && vis[i][m] == 0) bfs({ i,m });
        }

        for (int i = 1;i <= m;i++) {
            if (a[1][i] == '.' && vis[1][i] == 0) bfs({ 1,i });
            if (a[n][i] == '.' && vis[n][i] == 0) bfs({ n,i });
        }

        int ans = 0;
        for (int i = 1;i <= n;i++)
            for (int j = 1;j <= m;j++)
                if (a[i][j] == '.' && vis[i][j] == 0) {
                    bfs({ i, j });
                    ans++;
                }
        if (ans == 2) cout << "2020\n";
        else cout << "2018\n";
    }
}

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
#define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
    std::istringstream in(R"()");
    std::cin.rdbuf(in.rdbuf());
#endif
    int T = 1;
    //cin>>T;
    for (int i = 1;i <= T;i++) {
        solve();
    }
}